--
-- DESCRIPTION
--
-- @COMPANY **
-- @AUTHOR **
-- @DATE ${date} ${time}
--

---@type BP_Goal_C
local M = UnLua.Class()

local GM_RunnerClass = UE.UClass.Load("/Script/Engine.Blueprint'/MashRunner/Blueprints/GM_Runner.GM_Runner_C'")

-- function M:Initialize(Initializer)
-- end

-- function M:UserConstructionScript()
-- end

function M:ReceiveBeginPlay()
    self.Box.OnComponentBeginOverlap:Add(self, self.OnComponentBeginOverlap_BOX)

    self.GameMode = UE.UGameplayStatics.GetGameMode(self):Cast(GM_RunnerClass)
end

-- function M:ReceiveEndPlay()
-- end

-- function M:ReceiveTick(DeltaSeconds)
-- end

-- function M:ReceiveAnyDamage(Damage, DamageType, InstigatedBy, DamageCauser)
-- end

-- function M:ReceiveActorBeginOverlap(OtherActor)
-- end

-- function M:ReceiveActorEndOverlap(OtherActor)
-- end

function M:OnComponentBeginOverlap_BOX(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, FromSweep, SweepResult)
    local BP_RunnerClass = UE.UClass.Load("/Script/Engine.Blueprint'/MashRunner/Blueprints/BP_Runner.BP_Runner_C'")

    local Runner = OtherActor:Cast(BP_RunnerClass)
    if Runner then
        if self.Ripped == false then
            self.Ripped = true
            self:TriggerGoal()
            Runner:FinishRace()
        end
    end

end

-- 触发
function M:TriggerGoal()
    local NewSprite = LoadObject("/Script/Paper2D.PaperSprite'/MashRunner/PaperAssets/Goal/T_Goal_Ripped_Sprite.T_Goal_Ripped_Sprite'")
    self.PaperSprite:SetSprite(NewSprite)
    self.GameMode:AnnounceWinner(self.Lanelndex)
end

return M
